package light.head.dao.sys;

import java.io.Serializable;

import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.model.OrganDetails;

import org.springframework.stereotype.Service;
@Service
public class OrganDetailsDAO extends BaseDAO<OrganDetails, Serializable>{
	private static final String sql_queryOrganDetails = "FROM OrganDetails ods WHERE ods.oc = ?";
	
	public OrganDetails getByOc(Integer code){
		return (OrganDetails)super.get(sql_queryOrganDetails, code);
	}
	
	
	public RESULT update(OrganDetails ods) {
		if (null == ods || null == ods.getCode()) return RESULT.PARAMETER_ERROR;
		
		OrganDetails dbods = get(ods.getCode());
		if (null == dbods) {
			return RESULT.NOT_FIND;
		}
		
		if (null != dbods) {
			boolean ok = false;
			if ((isNotNull(ods.getAddress()) && !ods.getAddress().equals(dbods.getAddress())) || null == dbods.getAddress()) {
				ok = true;
				dbods.setAddress(ods.getAddress());
			}
			if ((isNotNull(ods.getEmail()) && !ods.getEmail().equals(dbods.getEmail())) || null == dbods.getEmail()) {
				ok = true;
				dbods.setEmail(ods.getEmail());
			}
			if ((isNotNull(ods.getFax()) && !ods.getFax().equals(dbods.getFax())) || null == dbods.getFax()) {
				ok = true;
				dbods.setFax(ods.getFax());
			}
			if ((isNotNull(ods.getSite()) && !ods.getSite().equals(dbods.getSite())) || null == dbods.getSite()) {
				ok = true;
				dbods.setSite(ods.getSite());
			}
			if ((isNotNull(ods.getLatitude()) && !ods.getLatitude().equals(dbods.getLatitude())) || null == dbods.getLatitude()) {
				ok = true;
				dbods.setLatitude(ods.getLatitude());
			}
			
			if ((isNotNull(ods.getLongitude()) && !ods.getLongitude().equals(dbods.getLongitude())) || null == dbods.getLongitude()) {
				ok = true;
				dbods.setLongitude(ods.getLongitude());
			}
			
			if ((isNotNull(ods.getPhone()) && !ods.getPhone().equals(dbods.getPhone())) || null == dbods.getPhone()) {
				ok = true;
				dbods.setPhone(ods.getPhone());
			}
			
			if ((null == dbods.getPostal()) || (null != ods.getPostal() && ods.getPostal().intValue() != dbods.getPostal().intValue())) {
				dbods.setPostal(ods.getPostal());
				ok = true;
			}
			
			if (ok) {
				return this.upd(dbods);
			}
			
		 }
		
		/// 不修改也返回成功
		return RESULT.SUCCESS;
	}
}
